#include <bits/stdc++.h>
using namespace std;
const int _ = 1e6 + 10;
const int __ = 2e6 + 10;
int n, arr[_], brr[__], pos[_], sum[_], minneqn[_], lef[_], val[_], tp, stk[_], dp[_];
inline void solve(void) {
    for (int i = 1; i <= n; i++) {
        pos[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        arr[i]++;
        if (arr[i] < 1 || arr[i] > n) {
            cout << -1;
            return;
        }
        if (pos[arr[i]]) {
            cout << -1;
            return;
        } else {
            pos[arr[i]] = i;
        }
    }
    brr[1] = 1;
    brr[2 * n + 1] = 1;
    for (int i = 2; i <= 2 * n; i++) {
        brr[i]++;
        if (brr[i] > i || brr[i] > 2 * n + 2 - i) {
            cout << -1;
            return;
        }
    }
    for (int i = 1; i <= n; i++) {
        sum[i] = 0;
        minneqn[i] = n + 1;
    }
    for (int i = 1; i <= n; i++) {
        if (arr[i] == n) {
            val[i] = 0;
        } else {
            val[i] = pos[arr[i] + 1];
        }
    }
    tp = 0;
    for (int i = 1; i <= n; i++) {
        while (tp && val[i] > val[stk[tp]]) tp--;
        if (tp) {
            minneqn[stk[tp]] = min(minneqn[stk[tp]], i);
        }
        stk[++tp] = i;
    }
    for (int i = 2, j = 1; i <= 2 * n; i++) {
        int r = j + brr[j] - 1;
        if (i <= r) {
            int k = (j << 1) - i;
            int d = r - i + 1;
            if (min(d, brr[i]) > min(d, brr[k])) {
                cout << -1;
                return;
            }
        }
        int ll = i - brr[i] + 1;
        int rr = i + brr[i] - 1;
        if (ll != 1 && rr != 2 * n + 1) {
            int lef = pos[((ll - 1) >> 1)];
            int rig = pos[((rr + 1) >> 1)];
            if (lef > rig) swap(lef, rig);
            minneqn[lef] = min(minneqn[lef], rig);
        }
        if (rr > r) {
            for (int p = max(r, i) + 1; p <= rr; p++) {
                if (!(p & 1)) {
                    int q = (i << 1) - p;
                    int pp = pos[p >> 1];
                    int qq = pos[q >> 1];
                    if (pp > qq) swap(pp, qq);
                    sum[pp]++;
                    sum[qq]--;
                }
            }
        }
    }
    lef[1] = 1;
    for (int i = 2; i <= n; i++) {
        sum[i] += sum[i-1];
        if (sum[i-1]) {
            lef[i] = lef[i-1];
        } else {
            lef[i] = i;
        }
    }
    lef[n+1] = n+1;
    for (int i = n - 1; i >= 1; i--) {
        minneqn[i] = min(minneqn[i], minneqn[i+1]);
    }
    for (int i = 1; i <= n; i++) {
        minneqn[i] = lef[minneqn[i]];
        if (minneqn[i] <= i) {
            cout << -1;
            return;
        }
    }
    for (int i = 1; i <= n; i++) {
        dp[i] = 0;
    }
    for (int i = 1; i <= n - 1; i++) {
        dp[i+1] = max(dp[i+1], dp[i]);
        dp[minneqn[i]] = max(dp[minneqn[i]], dp[i] + 1);
    }
    if (dp[n] >= 26) {
        cout << -1;
        return;
    } else {
        for (int i = 1; i <= n; i++) {
            cout << ((char) (97 + dp[pos[i]]));
        }
    }
}
int main() {
    freopen("string.in", "r", stdin);
    freopen("string.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int Testcases;
    cin >> Testcases;
    while (Testcases--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> arr[i];
        }
        for (int i = 2; i <= 2 * n; i++) {
            cin >> brr[i];
        }
        solve();
        if (Testcases) {
            cout << '\n';
        }
    }
    cout << endl;
    return 0;
}